﻿
CREATE PROCEDURE [dbo].[GL_CopyFromTemp]
@LastUpdate datetime
as
DELETE FROM GL WHERE DATE = @LastUpdate
INSERT INTO GL
SELECT 
       [Date],
       [Entity],
       [Filial],
       Sub.Id as SubsidiaryId,
       [Money],
       Sec.Id as SectorId,
       [Line],
       [Value],
       [TransactionType],
       [TransactionCode],
       [OPInput],
       [OPAuth],
       [Module],
       [Prove],
       [EventCode],
       [EventNumber],
       [ContabilityDate],
       [HistoricOne],
       [HistoricTwo],
       [ReportFlag]
 FROM GLTemp as GLTemp
INNER JOIN Subsidiary as Sub on GLTemp.Subsidiary = Sub.[Code]
INNER JOIN Sector as Sec on GLTemp.Sector = Sec.Code

DELETE FROM GLTemp